<?php

/**
 * Quext class: ActiveRecord for quext table
 *
 * @method Quext find($id)
 *
 * @author vbolshov
 */

namespace quext;

use km\db\ActiveRecord;

class Quext extends ActiveRecord {
	static protected $table = 'quext';
	static protected $defaults = array(
		'parent_id' => null,
		'position' => null,
		'title' => null,
		'html' => null,
	);
	static protected $parents = array(
		'parent' => array('quext\\Quext', 'parent_id')
	);
	static protected $children = array(
		'children' => array('quext\\Quext', 'parent_id')
	);
	/**
	 * @return Quext
	 */
	function getParentNode()
	{
		return parent::getParent('parent');
	}
	/**
	 * @return Select
	 */
	function getChildNodes()
	{
		return parent::getChildren('children');
	}
	static function getRootNodes()
	{
		return static::findAll('parent_id IS NULL')->order('title');
	}
	protected function createValidator()
	{
		return parent::createValidator()
			->addrequired('position', 'position is required')
			->addrequired('title', 'title is required')
			->addrequired('html', 'html is required');
	}
}